<template>
  <div class="">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <ProFilter v-model="filter.id" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <CustomerSelect v-model="filter.ctm_id" />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <el-date-picker
            v-model="filter.begin_create_time"
            placeholder="开始时间"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            size="small"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <el-date-picker
            v-model="filter.end_create_time"
            placeholder="结束时间"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            size="small"
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl">
          <el-select v-model="filter.state" size="small" style="width: 100%">
              <el-option
                v-for="item in states"
                :key="item.key"
                :label="item.value"
                :value="item.key"
              />
            </el-select>
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
          <el-button type="primary" size="small" @click="handleOut">导 出</el-button>
          <el-button
            type="primary"
            size="small"
            @click="handleDialog({
              dRef: 'pro',
              dTitle: '新增项目',
              dType: 'add',
              dField: dFieldPro
            })"
          >新 增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="app.loading" class="search-table" :data="list" border 
      :summary-method="getSummaries"
      show-summary
      fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="EQ单号" width="190px">
        <template slot-scope="{row}">
          {{ 'EQ'+row.id }}
        </template>
      </el-table-column>
      <el-table-column label="客户名称" width="220px" prop="lc_name" />
      <el-table-column label="项目名称" width="220px" prop="name" />
      <el-table-column label="成本" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.cost, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="报价金额 " align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.quoted_price, 2) }}
        </template>
      </el-table-column>
      <el-table-column label="议价金额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.negotiated_price, 2) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="订单金额" align="right" width="140px">
        <template slot-scope="{row}">
          {{ app.toFix(row.trading_price, 2) }}
        </template>
      </el-table-column> -->
      <el-table-column label="报价人" mwidth="180px" prop="su_quoted_name" />
      <!-- <el-table-column label="项目负责人" width="180px" prop="director" /> -->
      <el-table-column label="客户联系人" width="180px" prop="lcc_name" />
      <el-table-column label="客户电话" width="140px" prop="lcc_phone" />
      <el-table-column label="项目状态" align="center" width="90px" prop="name" :formatter="formatterState" />
      <el-table-column label="提交时间" align="center" width="150px" prop="create_time" />
      <el-table-column label="备注" min-width="260px" prop="remark">
        <template slot-scope="{row}">
          <span v-if="row.remark">{{ row.remark }} <br></span>
          <span v-if="row.bid_remark">{{ row.bid_remark }} <br></span>
          <span v-if="row.progress_remark">{{ row.progress_remark }} <br></span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item  v-if="row.state === 0"
                @click.native="handleDialog({...row, ...
                {dRef: 'pro', dTitle: '编辑项目', dType: 'edit', dField: dFieldPro}})"
              >编 辑</el-dropdown-item>
              <!-- <el-dropdown-item
                @click.native="handleDialog({...{pro_id: row.id}, ...
                {dRef: 'directors', dTitle: '项目负责人信息', dType: 'edit', dField: dFieldDirectors}})"
              >负责人</el-dropdown-item> -->
              <!-- <el-dropdown-item
                @click.native="handleDialog({...row, ...
                {dRef: 'bid', dTitle: '项目投标', dType: 'edit', dField: dFieldBid}})">投 标</el-dropdown-item> -->
              <el-dropdown-item  v-if="row.state === 0"
                @click.native="handleDialog({...row, ...
                {dRef: 'order', dTitle: '项目下单', dType: 'edit', dField: dFieldOrder}})"
              >项目状态</el-dropdown-item>
              <!-- <el-dropdown-item
                @click.native="handleDialog({...row, ...
                {dRef: 'progress', dTitle: '编辑进度', dType: 'edit', dField: dFieldProgress}})">进 度</el-dropdown-item> -->
              <el-dropdown-item  v-if="row.state === 0"
                @click.native="handleDialog({...{pro_id: row.id}, ...
                {dRef: 'visits', dTitle: '拜访记录信息', dType: 'edit', dField: dFieldVisits}})"
              >拜访记录</el-dropdown-item>
              <el-dropdown-item  v-if="row.state === 0"
                @click.native="files({e_id: row.id, type: '商务管理',
                                      db_type: 'logc_pro_archives'})"
              >附 件</el-dropdown-item>
              <el-dropdown-item @click.native="handleDelete(row)">删 除</el-dropdown-item>
              <el-dropdown-item  v-if="row.state === 0" @click.native="outData(row)">导 出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
    <Pro ref="pro" :get-data="getList" :info="dialog" />
    <Visits ref="visits" :get-data="getList" :info="dialog" />
    <!-- <Directors ref="directors" :get-data="getList" :info="dialog" /> -->
    <!-- <Progress ref="progress" :get-data="getList" :info="dialog" /> -->
    <Order ref="order" :get-data="getList" :info="dialog" />
    <!-- <Bid ref="bid" :get-data="getList" :info="dialog" /> -->
    <Cos ref="cos" :info="dialog" />
  </div>
</template>

<script>
import { pros, delPros, outPros } from '@/api/project'
import Dialog from './components/project-dialog'
import Pro from './components/pro-dialog'
// import Directors from './components/directors-dialog'
// import Progress from './components/progress-dialog'
import Order from './components/order-dialog'
// import Bid from './components/bid-dialog'
import Visits from './components/visits-dialog'
import ProFilter from '@/components/ProFilter'
import page from '@/utils/page'
import CustomerSelect from '@/myComponents/CustomerSelect'

export default {
  name: '',
  components: { ProFilter, Dialog, Order, Visits, Pro, CustomerSelect },
  extends: page,
  props: {
    reqList: {
      default: pros,
      type: Function
    },
    reqDel: {
      default: delPros,
      type: Function
    }
  },
  data() {
    return {
      // parameter: { state: 0 },
      price: {},
      states: [{key:2, value:'丢单'}, {key:0, value:'跟进'}],
      dField: ['id', 'name', 'ctm_id', 'su_track', 'remark'],
      dFieldDirectors: ['pro_id'],
      dFieldProgress: ['id', 'progress_remark', 'state'],
      dFieldOrder: ['id', 'order_time', 'order_remark', 'state'],
      // dFieldBid: ['id', 'cost', 'quoted_price', 'negotiated_price', 'trading_price', 'su_quoted', 'bid_remark'],
      dFieldVisits: ['pro_id'],
      dFieldPro: ['id', 'name', 'no', 'ctm_id', 'su_track', 'state', 'cost', 'quoted_price', 'negotiated_price',
        'trading_price', 'su_quoted', 'remark', 'bid_remark', 'progress_remark', 'order_remark', 'order_time',
        'tax_rate', 'contract_remark', 'budget_remark', 'create_time', 'oper_time']
    }
  },
  created() {
    this.$set(this.filter, 'state', 0)
    this.getList()
  },
  methods: {
    handleOut() {
      outPros({
        ...this.filter
      }).then(response => {
        this.out(response)
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    formatterState(e) {
      if (e.state === 0) {
        return '进展中'
      } else if (e.state === 1) {
        return '已成交'
      } else {
        return '未成交'
      }
    },
    getListAfter(e) {
      this.price = e.summary
    },
    getSummaries() {
      const sums = []
      sums[0] = '合计'
      sums[4] = this.app.toFix(this.price.cost, 2)
      sums[5] = this.app.toFix(this.price.quoted_price, 2)
      sums[6] = this.app.toFix(this.price.negotiated_price, 2)
      return sums
    }
  }
}
</script>
